package app.species.ANN;

import ec.util.MersenneTwisterFast;
import java.util.StringTokenizer;

public class AxonGene extends Gene {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6270175256203675981L;
	private double weight;
	private int startID, endID;
	private boolean disabled;
	private boolean mode;

	public AxonGene(int id, int start, int end, double w) {

		super(id);

		this.startID = start;
		this.endID = end;
		this.weight = w;
		this.disabled = false;

	}

	public AxonGene(int id, int start, int end, double w, boolean dis) {
		this(id, start, end, w, dis, true);
	}

	public AxonGene(int id, int start, int end, double w, boolean dis, boolean mode) {
		this(id, start, end, w);

		this.disabled = dis;
		this.mode = mode;

	}

	public AxonGene(int id, int start, int end, MersenneTwisterFast random) {

		this(id, start, end, 0.0);

		this.weight = random.nextDouble() * Axon.getMaxWeight() * random.nextSign();
	}

	public static AxonGene makeGeneFromString(String str) {

		StringTokenizer tokenizer = new StringTokenizer(str);
		int i, sid, eid;
		double w;
		boolean dis;

		tokenizer.nextToken();
		i = Integer.parseInt(tokenizer.nextToken());

		tokenizer.nextToken();
		sid = Integer.parseInt(tokenizer.nextToken());

		tokenizer.nextToken();
		eid = Integer.parseInt(tokenizer.nextToken());

		tokenizer.nextToken();
		w = Double.parseDouble(tokenizer.nextToken());

		tokenizer.nextToken();
		dis = Boolean.getBoolean(tokenizer.nextToken());

		return new AxonGene(i, sid, eid, w, dis);

	}

	public void setDisabled(boolean b) {
		this.disabled = b;
	}

	public boolean getDisabled() {
		return this.disabled;
	}

	public void addWeight(double delta) {
		this.weight += delta;
	}

	public double getWeight() {
		return this.weight;
	}

	public int getStartID() {
		return this.startID;
	}

	public int getEndID() {
		return this.endID;
	}

	public boolean getMode() {
		return mode;
	}

	public void setMode(boolean modus) {
		mode = modus;
	}

	public String toString() {

		return "ID: " + this.getID() + " StartID: " + this.startID + " EndID: " + this.endID + " Weight: "
				+ this.weight + " Mode: "+this.mode + " Disabled: " + this.disabled;

	}

}
